package com.blog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blog.dao.BookMapper;
import com.blog.model.Book;
import com.blog.service.interfaces.IBookService;
@Service("bookService")
public class BookService implements IBookService {
	@Autowired
	BookMapper bookMapper;
	
	public List<Book> getBooksList(String category){
		return bookMapper.selectByCategory(category);
	}
	
	public Integer addBook(Book book){
		return bookMapper.insert(book);
	}	

	public Integer delBookById(Integer id){
		return bookMapper.deleteByPrimaryKey(id);
	}

	public Integer delBookById(String string) {
		// TODO 自动生成的方法存根
		return bookMapper.deleteByPrimaryKey(Integer.valueOf(string));
	}
	
	public List<Book> checkExistTitle(String title,String category){
		return bookMapper.selectByTitleAndCategory(title,category);
	}
	
	public Book selectByBookId(Integer id){
		return bookMapper.selectByPrimaryKey(id);
	}
	
	public Integer updateBookInfo(Book record){
		return bookMapper.updateByPrimaryKeySelective(record);
	}
}
